<?php 
session_start();
include("db_connect.php")
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Basciautosales store the place where you can buy trade set build your own dream cars at its your ways" />
<meta name="description" content="Basciautosales store the place where you can buy trade set build your own dream cars at its your ways" />

<title>Shop</title>
<?php include("include/jquery.php");?>


<script>

function showMenu( divNum )
{ 
	$(".s"+divNum).slideToggle();
	$("#i"+divNum).toggle();
}
</script>

<script>
$(document).ready(function() {
});
</script>

</head>

<body> <div id=" msgbox"></div>

<div id="templatemo_wrapper">
	<!--header-->
		<?php include("include/header.php");?>
	<!--header-->
	
	
    <div id="templatemo_main">
   		<div id="sidebar" class="float_l">
        	<!---sidebox bottom-->
			<img src="images/mycart.png" />
            <div class="sidebar_box">
            	 
                <div class="content"> 
                	<div id="itemList"></div>
                </div>
				<br />
            </div>
			<img src="images/categories.png" />
			<div class="sidebar_box">
			   
                <div class="menu"> 
					<b>Spare Parts & Accessories</b><br />
                	<?php
					$query = mysql_query("SELECT * FROM tblbrand")or die(mysql_error());
					
					$display = '';
					while($row = mysql_fetch_array($query)){
							$brandid = $row['id'];
							$brandname = $row['brand'];
								$display .= '<div class="mhead"><img style="position: absolute; margin-top: 4px;" src="images/minus.png"
								 border="0" width="11" height="12" /> <img id="i'.$brandid.'" name="i'.$brandid.'" style="position: absolute; margin-top: 4px;" src="images/plus.png"
								border="0" width="11" height="12" /> &nbsp; &nbsp;<a href="javascript:showMenu('.$brandid.');"><font style="font-size: 12px;">' .$brandname.'</font></a></div>';
								
							$query2 = mysql_query("SELECT * FROM tblmodel")or die(mysql_error());			
							while($rows = mysql_fetch_array($query2)){
								
								if($brandid == $rows['brandId']){
							
								$display .= '<div id="submenu" class="s'.$brandid.'" style="display: none;"> <img style="position: absolute; margin-top: 3px;" src="images/img_tree_empty.png" /> &nbsp; &nbsp; <a href="shop.php?model='.$rows['modelname'].'" name="'.$rows['modelname'].'">'.$rows['modelname'].'</a><br /></div>';	
							
								}
								
						}
						
					}
					echo $display;
				?>
				</div>
			</div>
				
        </div><!--end sider-->
		
		<!--content--->
		<div id="shop-header">
		</div>
        <div id="content" class="float_r" style="background-color:#fff;">
        	
              <div class="fp_holder">
					<div id="shop_holder">								
							<!--for the pagination and data of the product-->
							<?php
								
								$tableName = "tblswaping";		
								$targetpage = "shop.php"; 	
								$limit = 100; 
								$mypage = "";
								$model = "";
								if(isset($_GET['page'])){
									$mypage= $_GET['page'];
								}
								if(isset($_GET['model'])){
									$model = $_GET['model'];
								}
								$query = "SELECT COUNT(*) as num FROM ".$tableName." WHERE  categories = 'Acccessories' AND model like '$model%' AND quantity !=0 AND addoff = '1' ";
								
								$total_pages = mysql_fetch_array(mysql_query($query));
								$total_pages = $total_pages['num'];
								
								$stages = 3;
								$page = mysql_real_escape_string($mypage);
								if($page){
									$start = ($page - 1) * $limit; 
								}else{
									$start = 0;	
									}	
								
								// Get page data
								$query1 = "SELECT * FROM $tableName WHERE categories like 'Acccessories%' AND model like '$model%' AND quantity !=0 AND addoff = '1' ORDER BY id DESC LIMIT $start, $limit ";
								 
								$result = mysql_query($query1);
								
								// Initial page num setup
								if ($page == 0){$page = 1;}
								$prev = $page - 1;	
								$next = $page + 1;							
								$lastpage = ceil($total_pages/$limit);		
								$LastPagem1 = $lastpage - 1;					
								
								
								$paginate = '';
								if($lastpage > 1)
								{	
									$paginate .= "<div class='paginate'>";
									// Previous
									if ($page > 1){
										$paginate.= "<a href='$targetpage?page=$prev'>previous</a>";
									}else{
										$paginate.= "<span class='disabled'>previous</span>";	}
									
									// Pages	
									if ($lastpage < 7 + ($stages * 2))	// Not enough pages to breaking it up
									{	
										for ($counter = 1; $counter <= $lastpage; $counter++)
										{
											if ($counter == $page){
												$paginate.= "<span class='current'>$counter</span>";
											}else{
												$paginate.= "<a href='$targetpage?page=$counter#ourcarshow'>$counter</a>";}					
										}
									}
									elseif($lastpage > 5 + ($stages * 2))	// Enough pages to hide a few?
									{
										// Beginning only hide later pages
										if($page < 1 + ($stages * 2))		
										{
											for ($counter = 1; $counter < 4 + ($stages * 2); $counter++)
											{
												if ($counter == $page){
													$paginate.= "<span class='current'>$counter</span>";
												}else{
													$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
											}
											$paginate.= "...";
											$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
											$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
										}
										// Middle hide some front and some back
										elseif($lastpage - ($stages * 2) > $page && $page > ($stages * 2))
										{
											$paginate.= "<a href='$targetpage?page=1'>1</a>";
											$paginate.= "<a href='$targetpage?page=2'>2</a>";
											$paginate.= "...";
											for ($counter = $page - $stages; $counter <= $page + $stages; $counter++)
											{
												if ($counter == $page){
													$paginate.= "<span class='current'>$counter</span>";
												}else{
													$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
											}
											$paginate.= "...";
											$paginate.= "<a href='$targetpage?page=$LastPagem1'>$LastPagem1</a>";
											$paginate.= "<a href='$targetpage?page=$lastpage'>$lastpage</a>";		
										}
										// End only hide early pages
										else
										{
											$paginate.= "<a href='$targetpage?page=1'>1</a>";
											$paginate.= "<a href='$targetpage?page=2'>2</a>";
											$paginate.= "...";
											for ($counter = $lastpage - (2 + ($stages * 2)); $counter <= $lastpage; $counter++)
											{
												if ($counter == $page){
													$paginate.= "<span class='current'>$counter</span>";
												}else{
													$paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}					
											}
										}
									}
												
											// Next
									if ($page < $counter - 1){ 
										$paginate.= "<a href='$targetpage?page=$next'>next</a>";
									}else{
										$paginate.= "<span class='disabled'>next</span>";
										}
										
									$paginate.= "</div>";		
								
								
								}
							 //echo $total_pages.' Results';
							 // pagination
							 echo $paginate;
							?>

					

							<?php 
							
							if(mysql_num_rows($result)<1){
								echo '<div style="margin-top:10px;"><h3 style="color:#ab141b;">No Item Found</h3></div>';
								die();
							}
								$on = true; 
							
								while($row = mysql_fetch_array($result))
								{
									$img = explode("+", $row['filename']);
								if($on){
							echo '<div class="boxgrid slideright">';
								$on = false;
							}
							else if($on){
							echo '<div class="boxgrid thecombo">';
								$on="";
							}
							else{
							echo '<div class="boxgrid slidedown">';
								$on = true;
							}


							echo '<img class="cover" src="images/vehicles/'.$img[0].'"/>';
							
							echo '<div class="description">';
									echo '<p align="center" style="color:#ab141b; font-size:13px; " ><b>'.$row['name'].'</b></p>';
									echo '<label><b>Brand: &nbsp;</b></label>';
									echo '<label>'.$row["brand"].'</label>';
									echo '<br/>';
									
									echo '<label><b>Model: &nbsp;</b></label>';
									echo '<label>'.$row['model'].'</label>';
									echo '<br/>';
									
									echo '<label><b>Condition: &nbsp;</b></label>';
									echo '<label>'.$row['conditions'].'</label>';
									echo '<br/>';
									
									echo '<label><b>Part: &nbsp;</b></label>';
									echo '<label>'.$row['cparts'].'</label>';
									echo '<br/>';
									
									echo '<label><b>Price: &nbsp;</b></label>';
									echo '<label><img align="top" src="images/p12.gif" height="14" width="14" />'.$row['price'].'</label>';
									echo '<br/>';
									
									echo '<label><b>Qty: &nbsp;</b></label>';
									echo '<label>'.$row['quantity'].'</label>';
									echo '<br/><br/>';
									
									echo '<a href="preview.php?from=index+&pageid='.$row['id'].'" >See more..</a>';
									echo '<input type="hidden" value="'.$row['id'].'" id="'.$row['id'].'"></input>' ;
									if(isset($_SESSION['id']) && isset($_SESSION['type']) ){
										
										if($_SESSION['type']== 1)
										{
										
										}
										else{
											echo '<input align="right" title="add to cart" type="image" src="images/ico_basket.png" class="addcartimg" onclick="add2cart('.$row['id'].')" name="'.$row['id'].'"></input>';
										}
										
									}
									else{
										echo '<input align="right" title="add to cart" type="image" src="images/ico_basket.png" class="addcartimg" onclick="add2cart('.$row['id'].')" name="'.$row['id'].'"></input>';
								
									}
									
								echo '</div>';
								echo '</div>';
							
								}
							
							?>
						<!--isa pa sa baba-->
					  
						
					   
					<!--end for the pagination and data of the product-->
					
					
					
				</div><!--end of shop_holder-->
				
			</div><!--end of fp_holder-->
				
		</div>
        
		
        <div class="cleaner"></div>
    </div> <!-- END of templatemo_main -->
    
     <!--footer-->
	<?php include("include/footer.php");?>
    
</div> <!-- END of templatemo_wrapper -->




</div>
</body>
</html>